// https://leetcode.cn/problems/plus-one/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {
        int n = digits.size();
        vector<int> revDigits;
        for (int i = n - 1; i >= 0; i--) {
            revDigits.push_back(digits[i]);
        }

        int carray = 1;
        for (int i = 0; i < n; i++) {
            int sum = carray + revDigits[i];
            carray = sum / 10;
            revDigits[i] = sum % 10;
        }
        if (carray) {
            revDigits.push_back(carray);
        }

        reverse(revDigits.begin(), revDigits.end());
        return revDigits;
    }
};